package com.xiaojiehzu.jex.client.config;

/**
 * @author 朱小杰
 * 时间 2017-11-05 .16:12
 * 说明 ...
 */
public class SystemPropertyConfigLoader implements ConfigLoader {
    private final static String SERVER_ADDRESS_KEY = "serverAddress";
    private final static String APP_NAME_KEY = "appName";


    @Override
    public boolean isSupport() {
        return getConfiguration() != null;
    }

    @Override
    public JexConfiguration getConfiguration() {
        String temp = System.getProperty(SERVER_ADDRESS_KEY, null);
        String[] serverAddress = null;
        if (temp != null) {
            serverAddress = temp.split(",");
        }
        String appName = System.getProperty(APP_NAME_KEY, null);
        if (serverAddress != null && appName != null) {
            JexConfiguration jexConfiguration = JexConfiguration.buildJexConfiguration(serverAddress, appName);
            return jexConfiguration;
        } else {
            return null;
        }
    }


}
